<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath()+request.getServletPath().substring(0,request.getServletPath().lastIndexOf("/")+1);
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户注册</title>
</head>
<script type="text/javascript" src="<%=basePath%>js/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	var isSubmit = true;
	var isUserName = true;
	var isPassword = true;
	
	$("#username").focusout(function(){
		if(!$(this).val()){
			isUserName = false;
			$("#usernameMessage").html("<font color='red'>用户名不能为空</font>");
		}else{
			isUserName = true;
			$("#usernameMessage").html("");
		}
	});
	
	$("#password").focusout(function(){
		if(!$(this).val()){
			isPassword = false;
			$("#passwordMessage").html("<font color='red'>密码不能为空</font>");
		}else{
			isPassword = true;
			$("#passwordMessage").html("");
		}
	});
	
	$("#confpassword").focusout(function(){
		if(!$(this).val() || $(this).val() != $("#password").val()){
			isConfPassword = false;
			$("#confPasswordMessage").html("<font color='red'>两次密码输入不一致</font>");
		}else{
			isConfPassword = true;
			$("#confPasswordMessage").html("");
		}
	});
	$("#register").click(function(){
		isSubmit = isUserName&&isPassword&&isConfPassword;
		if(isSubmit){
			$("#regForm").submit();
		}else{
			alert("请检查输入是否正确");
		}
	})
});
</script>
<body>
<div style="height:300px;wight:1px;"></div>
	<form action="<%=basePath %>user/save" method="post" id="regForm">
		<table align="center" cellpadding="4" cellspacing="4" border="0" width="800px;"> 
			<tr><td align="right" width="200px;">用户名：</td><td width="250px"><input type="text" name="username" id="username" value="" size="40"/><td><div id="usernameMessage"></div></td></tr>
			<tr><td align="right" width="200px;">真实姓名：</td><td width="250px"><input type="text" name="realname" id="realname" value="" size="40"/><td><div id="realnameMessage"></div></td></tr>
			<tr><td align="right">密码：</td><td><input type="password" name="password" id="password" value="" size="40"/></td><td><div id="passwordMessage"></div></td></tr>
			<tr><td align="right">确认密码：</td><td><input type="password" name="confpassword" id="confpassword" value="" size="40"/></td><td><div id="confPasswordMessage"></div></td></tr>
			<tr><td colspan="3" align="center"><input type="button" value="注册" id="register"/><input type="reset" value="重置"/></td></tr>
		</table>
	</form>
</body>
</html>